package com.custom.base.adapter

import android.app.Activity
import android.content.res.TypedArray
import android.graphics.Color
import android.view.View
import android.view.ViewGroup
import android.widget.TextView

import com.custom.base.base.BaseAdapter
import com.custom.base.R

/**
 * 作者：
 * 时间：12/15/20
 * 描述：
 */
class AdaptiveHorizontalTextViewAdapter(listModel: ArrayList<String>, activity: Activity,attributes: TypedArray?) :
    BaseAdapter<String>(listModel, activity) {

    private var paddingLefta = 0
    private var paddingRighta = 0
    private var paddingTopa = 0
    private var paddingBottoma = 0
    private var bgColor = 0
    private var textColor = 0
    private var textSize = 0f
    init {
        attributes?.apply {
            paddingLefta = getDimensionPixelSize(R.styleable.AdaptiveHorizontalTextView_paddingLeft,14)
            paddingRighta = getDimensionPixelSize(R.styleable.AdaptiveHorizontalTextView_paddingRight,14)
            paddingTopa = getDimensionPixelSize(R.styleable.AdaptiveHorizontalTextView_paddingTop,7)
            paddingBottoma = getDimensionPixelSize(R.styleable.AdaptiveHorizontalTextView_paddingBottom,7)
            textSize = getDimension(R.styleable.AdaptiveHorizontalTextView_textSize,16f)
            textColor = getColor(R.styleable.AdaptiveHorizontalTextView_textColor, Color.parseColor("#FF333333"))
            bgColor = getColor(R.styleable.AdaptiveHorizontalTextView_bgColor, R.drawable.layer_gray_corner_item_single)
        }
    }

    override fun getLayoutId(position: Int, convertView: View?, parent: ViewGroup?): Int {
        return R.layout.view_adaptivehorizontaltextview
    }

    override fun bindData(position: Int, convertView: View?, parent: ViewGroup?, model: String) {
        val tv = find<TextView>(R.id.view_adaptivehorizontaltextview_tv, convertView)
        tv.text = model
        tv.textSize = textSize
        tv.setTextColor(textColor)
        tv.setPadding(paddingLefta,paddingTopa,paddingRighta,paddingBottoma)
        tv.setBackgroundColor(bgColor)
    }
}
